#!/bin/sh

GAMEDIR=${PWD}
gamedir="$GAMEDIR"
cd "$gamedir/gamedata"
monodir="$HOME/mono"
monofile="$gamedir/libs/mono-6.12.0.122-aarch64.squashfs"
mkdir -p "$monodir"
umount "$monodir" || true
mount -t squashfs "$monofile" "$monodir"
rm -rf ~/.local/share/Lode\ Runner\ Online
mkdir -p ~/.local/share
ln -sfv "$GAMEDIR/savedata" ~/.local/share/Lode\ Runner\ Online
rm -f System*.dll mscorlib.dll FNA.dll Mono.*.dll

export MONO_PATH="$gamedir/dlls"
export LD_LIBRARY_PATH="$gamedir/libs":"${monodir}/lib":$LD_LIBRARY_PATH
export PATH="$monodir/bin":"$PATH"
export FNA3D_FORCE_DRIVER=OpenGL
export FNA3D_OPENGL_FORCE_ES3=1
export FNA3D_OPENGL_FORCE_VBO_DISCARD=1

SDL_GAMECONTROLLERCONFIG_FILE="./gamecontrollerdb.txt" & #./gptokeyb -k "mono" -c "./LODERUNN.gptk" &
sleep 1
export LD_LIBRARY_PATH=$gamedir/libs:$monodir/lib:$usr/trimui/lib:$LD_LIBRARY_PATH
mono "$gamedir/gamedata/LODERUNN.exe" 2>&1 | tee -a $gamedir/log.txt
kill -9 $(pidof gptokeyb) 
umount "$monodir"

